const fs = require("fs");
const path = require("path");
// 同步操作处理错误，使用try..catch
try {
  let data = fs.readFileSync(path.resolve(__dirname, "./test.txt"), "utf-8");
  console.log(data, "readFileSyn");
} catch (err) {
  console.error(err);
}
